package com.easyselection.config;

import com.easyselection.interceptor.JsonWebTokenInterceptor;
import com.easyselection.interceptor.LoginInterceptor;
import com.easyselection.interceptor.RefreshTokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MvcConfig implements WebMvcConfigurer {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
//        //添加登录拦截器, 并且排除不需要拦截的路径 LoginInterceptor后执行
//        registry.addInterceptor(new LoginInterceptor()).excludePathPatterns(
//                "/user/login",
//                "/user/code",
//                "/blog/hot",
//                "/shop/**",
//                "/shop-type/**",
//                "/upload/**",
//                "/voucher/**"
//        ).order(1);
//
//        //拦截所有请求 RefreshTokenInterceptor先执行
//        registry.addInterceptor(new RefreshTokenInterceptor(stringRedisTemplate)).order(0);


        registry.addInterceptor(new JsonWebTokenInterceptor(stringRedisTemplate)).excludePathPatterns(
                "/user/login",
                "/user/code",
                "/blog/hot",
                "/shop/**",
                "/shop-type/**",
                "/upload/**",
                "/voucher/**"
        );
    }
}
